package com.coooliang.apibook;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.IOException;

public class HelloApplication extends Application {
    double sceneX;
    double sceneY;

    @Override
    public void start(Stage stage) throws IOException {
        stage = FXMLLoader.load(getClass().getResource("hello-view.fxml"));
        stage.centerOnScreen();
        stage.initStyle(StageStyle.TRANSPARENT);//无标题栏
//        stage.getScene().setFill(Paint.valueOf("#ffffff00"));//背景色透明

        Image icon = new Image(this.getClass().getResourceAsStream("/assets/white_logo.png"));
        stage.getIcons().add(icon);

        Stage finalStage = stage;
        finalStage.getScene().setOnMousePressed(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                sceneX = mouseEvent.getScreenX() - finalStage.getX();
                sceneY = mouseEvent.getScreenY() - finalStage.getY();
            }
        });

        finalStage.getScene().setOnMouseDragged(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                finalStage.setX(mouseEvent.getScreenX()-sceneX);
                finalStage.setY(mouseEvent.getScreenY()-sceneY);
            }
        });

        finalStage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}